package com.recruit.g1.job.mapper;

import com.recruit.g1.pojo.job.entity.Job;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface InterestedJobsMapper {
    @Select("SELECT ui.id,  j.city_id,  j.company_id, j.job_name, j.title, j.description,  j.requirements, j.salary_range, j.location, j.post_time,  j.status\n" +
            " FROM userinterestedin ui INNER JOIN  job j ON ui.job_id = j.id\n" +
            " WHERE ui.user_id = #{userId, jdbcType=INTEGER}")
    List<Job> selectInterestedJobs(@Param("userId") Long userId);

    @Select("<script>SELECT ui.id, j.city_id, j.company_id, j.job_name, j.title, j.description, j.requirements, j.salary_range, j.location,j.post_time, j.status\n" +
            " FROM userinterestedin ui INNER JOIN job j ON ui.job_id = j.id\n" +
            "       <where>\n" +
            "           <if test=\"jobId!=null\">\n" +
            "               ui.job_id = #{jobId, jdbcType=INTEGER}\n" +
            "           </if>\n" +
            "           <if test=\"userId!=null\">\n" +
            "               AND ui.user_id = #{userId, jdbcType=INTEGER}\n" +
            "           </if>\n" +
            "       </where></script>")
    List<Job> selectInterestedJob(@Param("userId")Long userId, @Param("jobId") Long jobId);

    //本方法因为没有处理user模块登录成功，本模块获取不到登录用户的问题，所以本方法目前还无法使用
    @Delete("DELETE FROM userinterestedin WHERE job_id = #{jobId, jdbcType=INTEGER} and user_id=#{userId}")
    void deleteInterestedJobs(Long jobId,Long userId);
}
